<template>
  <div style="padding:10px">
    <div style="margin: 10px  0">
      <!--      功能区域-->
<!--      <el-button type="primary" @click="add"></el-button>-->

    </div>

    <div style="margin: 10px 0">
      <!--      搜索区域-->
      <el-input v-model="search" placeholder="通过用户名或真实姓名查找"  style="width: 20%" clearable @input="change($event)" />
      <el-button type="primary" style="margin-left: 5px" @click="load">查询</el-button>
    </div>
    <!--    <el-button>按钮</el-button>-->
    <el-table :data="tableData" border stripe style="width: 100%">
      <el-table-column prop="id" sortable label="ID" width="50px" />
      <el-table-column prop="username" label="用户名" width="100px" />
      <el-table-column prop="name" label="真实姓名"  width="100px"/>
      <el-table-column prop="phone" label="手机号" width="120px" />
      <el-table-column prop="gname" label="商品名" width="150px"/>
      <el-table-column prop="price" label="价格" width="80px"/>
      <el-table-column prop="count" label="数量" width="60px"/>
      <el-table-column prop="ctime" label="购买时间" width="180px"/>
      <el-table-column prop="buyaddress" label="购买地址" width="150px"/>
      <el-table-column label="订单状态"  width="100px">
        <template #default="scope">
          {{ scope.row.status === 0 ? '未取货' : '已取货' }}
        </template>
      </el-table-column>

      <el-table-column label="操作">
        <template #default="scope">
          <el-popconfirm title="确定删除吗？" @confirm="handleDelete(scope.row.id)">
            <template #reference>
              <el-button type="danger" size="small" >删除</el-button>
            </template>
          </el-popconfirm>
          <el-button  @click="handlepick(scope.row.id)" size="small" type="success" v-if="scope.row.status==0">取货</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div style="margin: 10px 0">
      <el-pagination
          v-model:currentPage="currentPage"
          v-model:page-size="pageSize"
          :page-sizes="[5, 10, 15, 20]"
          :small="small"
          :disabled="disabled"
          :background="background"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>


import request from "../utils/request";

export default {
  name: 'Order',

  components: {

  },
  data(){
    return{
      form:{},
      tableData,
      currentPage:1,
      pageSize:10,
      total:10,
      dialogVisible:false,
    }
  },
  created() {//加载方法
    console.log(tableData)
    this.load()
  },
  methods:{

    load(url, config){
      request.get("/api/order",{
        params:{
          pageNum: this.currentPage,
          pageSize: this.pageSize,
          search: this.search
        }
      }).then(res => {
        console.log(res)
        this.tableData = res.data.records
        this.total = res.data.total
      })
    },

    handleSizeChange(){
      this.load()
    },
    handleCurrentChange(){
      this.load()
    },
    handleDelete(id){
      console.log(id)
      request.delete("/api/order/"+ id).then(res => {
        if (res.code == '200'){
          this.$message({
            type:"success",
            message:"删除成功"
          })
        }else {
          this.$message({
            type: "error",
            message: res.msg
          })
        }
        this.load()//重新加载删除之后的
      })
    },
    handlepick(id){
      request.put("/api/order/"+ id).then(res => {
        if (res.code == '200'){
          this.$message({
            type:"success",
            message:"成功"
          })
        }else {
          this.$message({
            type: "error",
            message: res.msg
          })
        }
        this.load()//重新加载删除之后的
      })
    },

    change(e){
      this.$forceUpdate()
    },

  }
}
const tableData = [

]

</script>
